# -*- coding: utf-8 -*-
"""
Calculate non-N bases genome size for MACS2 call peaks 

Usage: effective_genome_size.py genome.fasta
"""

import sys
base=[]

def cal_gsize(genome):
    with open(genome, 'r') as g:
        for line in g:
            line = line.strip().upper()
            if not line.startswith(">"):
                A = line.count("A")
                T = line.count("T")
                C = line.count("C")
                G = line.count("G")
                #extend() 函数用于在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）
                base.extend([A, T, C, G])
    
        print("effective_genome_size =", sum(base))
    
if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: effective_genome_size.py genome.fasta")
    genome = sys.argv[1]
    cal_gsize(genome)